package com.alt.www.sort;

import java.util.Arrays;

/**
 * Created by 27340 on 2017/4/6.
 */
public class InsertSort {
    public static void sort(int array[]){
        //index获取排序用的数据，同时起到哨兵的作用
        for(int index=1;index<array.length;index++){
            for(int sortIndx=0;sortIndx<index&&array[index]<array[sortIndx];sortIndx++){
               int temp = array[index];
               for(int i=index;i>sortIndx;i--){
                   array[i] = array[i-1];
               }
                array[sortIndx]=temp;
            }
        }
    }
    public static void main(String[] args){
        int[] arrays = {10,9,8,7,6,5,4,3,2,1,0};
        sort(arrays);
        System.out.print(Arrays.toString(arrays));
    }
}
